package logic

import (
	"context"
	"errors"
	"mooc_srv/models/mysql"

	"mooc_srv/internal/svc"
	"mooc_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrderLogic {
	return &UpdateOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateOrderLogic) UpdateOrder(in *order.UpdateOrderRequest) (*order.UpdateOrderResponse, error) {
	// todo: add your logic here and delete this line
	o := mysql.Order{}
	err := o.UpdateOrder(in.OrderSn, in.OrderStatus)
	if err != nil {
		logx.Info("修改订单状态失败", err)
		return nil, errors.New("修改订单状态失败")
	}

	return &order.UpdateOrderResponse{}, nil
}
